    function getTodayDate()
    {
        var date = new Date();
        var dateStr = date.format("yyyy-MM-dd");
        return dateStr;
    }
    function setTodayDate(typeStr)
    {
        $("#date" + typeStr).val(getTodayDate());
    }
    function AddTurnover(money,remark,date,from,to,type,catid)
    {
        var url = "phps/AddTurnover.php?";
        url = AddParam(url,"money",money);
        url = AddParam(url,"catid",catid); 
        url = AddParam(url,"from",from);
        url = AddParam(url,"to",to);
        url = AddParam(url,"time",date);
        url = AddParam(url,"remark",remark);
        url = AddParam(url,"type",type);
        console.log(url);
        $.get(url);
    }
    function saveTurnover(type)
    {
        var typeStr = getTypeStr(type);
        var money = $("#money" + typeStr).val();
        var cat = $("#categoryselect" + typeStr).val();
        var from = 0;
        var to = 0;
        if(type == 0)
        {
            from = $("#accountselect" + typeStr).val();
        } else if(type == 1)
        {
            to = $("#accountselect" + typeStr).val();
        } else if(type == 2)
        {
            from = $("#accountselect" + typeStr + "from").val();
            to = $("#accountselect" + typeStr + "to").val();
        }
        
        var date = $("#date" + typeStr).val();
        var remark = $("#remark" + typeStr).val();
       AddTurnover(money,remark,date,from,to,type,cat);
        
    }
    function getTypeStr(type)
    {
        typeStr = "";
        if(type == 0)
        {
            typeStr = "outgo";
        } else if(type == 1)
        {
            typeStr = "income";
        } else if(type == 2)
        {
            typeStr = "transfer"
        }
        return typeStr;
    }
    $("#pageAddIncome").live('pageinit', function() {
        InitAddTurnover(1);
    });
    $("#pageAddOutgo").live('pageinit', function() {
        InitAddTurnover(0);
    });
    $("#pageAddTransfer").live('pageinit', function() {
        InitAddTurnover(2);
    });
    function InitAddTurnover(type)
    {
       // alert("InitAddTurnover");
         //   var datamodel = new DataModel();
        datamodel.init();
         var typeStr = "";

       typeStr = getTypeStr(type);
        
        setTodayDate(typeStr);
        ///////////////////////////////////////////////////////////////////////
        if(type != 2)
        {
             //生成类别选择框
                var categoryselectid = "#categoryselect";
                categoryselectid += typeStr;

                for(var categoryid in datamodel.categorys)
                {
                    var category = datamodel.categorys[categoryid];
                    if(category.type == type)
                    {
                        var oneSelect = "<option value='{0}'>{1}</option>"
                        oneSelect = oneSelect.format(category.id,category.name);
                        $(categoryselectid).append(oneSelect);
                    }
                    
                }
              
               $(categoryselectid).val(0).selectmenu("refresh");
        }
       
        
            ///////////////////////////////////////////////////////////////
            var accountselectid = "#accountselect";
            accountselectid += typeStr;

            for(var accountid in datamodel.accounts)
            {
                var account = datamodel.accounts[accountid];
                var oneSelect = "<option value='{0}'>{1}</option>"
                oneSelect = oneSelect.format(account.id,account.name);
                if(type == 2)
                {
                    $(accountselectid + "from").append(oneSelect);
                    $(accountselectid + "to").append(oneSelect);
                } else 
                {
                    $(accountselectid).append(oneSelect);
                }
                
            }
            if(type == 2)
            {
                $(accountselectid + "from").val(0).selectmenu("refresh");
                $(accountselectid + "to").val(0).selectmenu("refresh");
            } else 
            {
                $(accountselectid).val(0).selectmenu("refresh");
            }
            
            
            $("#save" + typeStr).click(function(){
                saveTurnover(type);
            })
    }